//
//  YDBuyStrategyCell.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/15.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDBuyStrategyCell.h"

@interface YDBuyStrategyCell()
//分割线
@property (nonatomic , weak) UIView *lineView;




@end


@implementation YDBuyStrategyCell




+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *buyStrategyCell = @"YDBuyStrategyCell";
    YDBuyStrategyCell *cell = [tableView dequeueReusableCellWithIdentifier:buyStrategyCell];
    if (cell == nil) {
        cell = [[YDBuyStrategyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:buyStrategyCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.backgroundColor = [UIColor whiteColor];
        
        [self lineView];
        
        [self cateLabel];
        
        [self questionImage];
        
        [self accImage];
        
        [self detailLabel];
        
        [self autoSwitch];
        
    }
    return self;
}
//cateLabel
-(UILabel *)cateLabel
{
    if (_cateLabel == nil) {
        UILabel *cateLabel = [[UILabel alloc] init];
        [self.contentView addSubview:cateLabel];
        cateLabel.textColor = [UIColor colorWithHexString:blueyGrey];
        cateLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        cateLabel.textAlignment = NSTextAlignmentRight;
        cateLabel.text = @"";
        [cateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(rate375(10));
            make.centerY.equalTo(self);
        }];
        _cateLabel = cateLabel;
    }
    return _cateLabel;
}
-(UIImageView *)questionImage
{
    if (_questionImage == nil) {
        UIImageView *questtionImage = [[UIImageView alloc] init];
        [self.contentView addSubview:questtionImage];
        questtionImage.userInteractionEnabled = YES;
        [questtionImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.cateLabel.mas_right).offset(rate375(6));
            make.centerY.equalTo(self);
        }];
        questtionImage.image = [UIImage imageNamed:@"zhujie"];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick)];
        [questtionImage addGestureRecognizer:tap];
        
        _questionImage = questtionImage;
    }
    return _questionImage;
}
-(void)tapClick
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(buyStrategyCellQuestionImageClick:)]) {
        [self.delegate buyStrategyCellQuestionImageClick:self];
    }
}

- (void)swicthDidSwitch:(UISwitch *)sw
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(swicthDidSwitch:)]) {
        [self.delegate swicthDidSwitch:self.autoSwitch];
    }
}
-(UIImageView *)accImage
{
    if (_accImage == nil) {
        UIImageView *accImage = [[UIImageView alloc] init];
        [self.contentView addSubview:accImage];
        accImage.image = [UIImage imageNamed:@"wode-gd-grey"];
        [accImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.right.equalTo(self).offset(-rate375(20));
        }];
        _accImage = accImage;
    }
    return _accImage;
}


-(UILabel *)detailLabel
{
    if (_detailLabel == nil) {
        UILabel *detailLabel = [[UILabel alloc] init];
        [self.contentView addSubview:detailLabel];
        detailLabel.textColor = [UIColor colorWithHexString:dark];
        detailLabel.font = [UIFont systemFontOfSize:font16ScreenWRate * LKScreenW];
        detailLabel.textAlignment = NSTextAlignmentRight;
        detailLabel.text = @"hhaha";
        [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.accImage.mas_left).offset(-5);
            make.centerY.equalTo(self);
        }];
        _detailLabel = detailLabel;
    }
    return _detailLabel;
}

-(UIView *)lineView
{
    if (_lineView == nil) {
        UIView *lineView = [[UIView alloc] init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = NumberColor(247, 247, 247);
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self);
            make.height.equalTo(@1);
            make.left.equalTo(self).offset(10);
            make.right.equalTo(self).offset(-10);
        }];
        
        
        _lineView = lineView;
    }
    return _lineView;
}

-(UISwitch *)autoSwitch
{
    if (_autoSwitch == nil) {
        _autoSwitch = [UISwitch new];
        _autoSwitch.onTintColor = [UIColor colorWithHexString:fadedOrange];
        [self.contentView addSubview:_autoSwitch];
        [_autoSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@(-rate375(37)));
            make.centerY.equalTo(self.contentView);
        }];
        [_autoSwitch setOn:YES];
        [_autoSwitch addTarget:self action:@selector(swicthDidSwitch:) forControlEvents:UIControlEventValueChanged];
        
        _autoSwitch.transform = CGAffineTransformMakeScale(rate375(60)/60, isPhoneX ? rateX812(30)/30 :rate750(30)/30);
    }
    return _autoSwitch;
}

@end
